<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>rooms.jmpup.com</title>
    <meta name="author" content="Peter Kishalov" />
    <meta name="description" content="" />
    <meta name="keywords" content="iq IQ logic puzzle online entertainment mind cracking smullyan" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8; no-cache" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
  </head>
  <body>

<table cellspacing="0px" cellpadding="0px">
<tr class="title"><td>
rooms.JMPUP.com
</td></tr>

<?php
$seed = (int)$_POST['seed'];
$level = (int)$_POST['level'];
if( $level < 0 ) $level = 0;
$rcnt = (int)$_POST['rcnt'];
$rank = (int)$_POST['rank'];
$door_choice = (int)$_POST['doors'];
       
$output = shell_exec( "cd /home/petkish/executables && ./doors $seed $level check" );

$subjects = explode( "&\n", $output );
$doors = explode( '#', $subjects[0] );
$dcount = sizeof($doors) - 1;
if( sizeof($subjects) > 1 ){
$people = explode( '#', $subjects[1] );
$pcount = sizeof($people) - 1;
}else $pcount = 0;

$trapped = FALSE;
for( $i = 1; $i < sizeof($doors); ++$i ){
$dlines = explode( "\n", $doors[$i] );
$door = explode( ';', $dlines[0] );
if( $i == $door_choice ){
if( $door[3] == 0 ) $trapped = TRUE;
break;
}
}

$bitten = 0;
$spelled = 0;
$taxed = 0;
for( $i = 1; $i < sizeof($people); ++$i ){
$plines = explode( "\n", $people[$i] );
$person = explode( ';', $plines[0] );
if( $person[4] == '1' ){
switch($person[1]){
case 'human':
if( $_POST['p'.$i] == 'enemy' ){ 
++$taxed;
$rank -= 5;
}
break;
case 'wizard':
if( $_POST['p'.$i] == 'enemy' ){
++$spelled; 
$rank -= 10;
}
break;
case 'vampire':
if( $_POST['p'.$i] == 'friend' ){
++$bitten;
$rank -= 10;
}
break;
}
}
}

echo '<tr class="content"><td>';
if($trapped || $spelled > 0 ){
$level = 0;
echo '<img src="images/return.png"/></td></tr>';
if($trapped) echo '<tr class="content"><td><b>You got into a trap!</b></td></tr>';
}else{
echo '<img src="images/down.png"/></td></tr><tr class="content"><td><b>You have made it to the next room!</b></td></tr>';
$level += 3;
if($level > 100) $level = 100;
}

$rank_up = TRUE;
if($bitten > 0){
$rank_up = FALSE;
echo '<tr class="content"><td><b>You were bitten by a vampire'; 
if($bitten > 1) echo ' '.$bitten.' times'; 
echo ', because you treated him as your friend!</b><br/>Your immune system takes 10 rank points for each bite!</td></tr>';
}

if($spelled > 0){
$rank_up = FALSE;
echo '<tr class="content"><td><b>';
if($spelled == 1) echo 'A wizard puts a spell on you for treating him as an enemy!';
else echo 'Wizards put a spell on you for treating them as enemies '.$spelled.' times!';
echo '</b><br/>You were returned to the beginning, and fined 10 rank points for each mistake.</td></tr>';
}

if($taxed > 0){
$rank_up = FALSE;
echo '<tr class="content"><td><b>You tried to treat human as an enemy';
if($taxed > 1) echo ' '.$taxed.' times';
echo '!</b><br/>Your rank is fined by 5 points each time you do this!</td></tr>';
}

if($rank_up){
$rank += 3;
if($rank > 100) $rank = 100;
}else if($rank < 0) $rank = 0;

$seed = time();
++$rcnt;

if( $rank < 10 ) $rankstr = "jigsaw bunny"; 
else if( $rank < 20 ) $rankstr = "sudoku kid"; 
else if( $rank < 30 ) $rankstr = "tangram turtle";
else if( $rank < 40 ) $rankstr = "tetris teen"; 
else if( $rank < 50 ) $rankstr = "sokoban samurai"; 
else if( $rank < 60 ) $rankstr = "crossword cracker";
else if( $rank < 70 ) $rankstr = "flexagon freak";
else if( $rank < 80 ) $rankstr = "checkers champ";   
else if( $rank < 90 ) $rankstr = "rubiks ranger"; 
else $rankstr = "the chosen one";

echo '<tr class="content"><td><table><tr><td>Your rank:</td><td>'.$rankstr.' ('.$rank.')</td></tr>';
echo '<tr><td>Difficulty level:</td><td>'.$level.'%</td></tr>';
echo '<tr><td>Rooms passed:</td><td>'.$rcnt.'</td><tr></table></td></tr>';
echo '<tr class="content"><td><a href="room.php?seed='.$seed.'&level='.$level.'&rcnt='.$rcnt.'&rank='.$rank.'">Continue</a></td></tr>';       
?>

<tr class="packshot"><td>
Copyright &copy; Peter Kishalov, 2010.
</td></tr></table>
</body>
</html>
